/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年10月5日
 */
package com.massyframework.beanskin.service.crypto;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.util.Objects;

/**
 * 封装数据签名的相关方法
 * 
 * @author huangkh
 *
 */
public abstract class SignatureUtils {

	public static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
    public static final String END_CERT = "-----END CERTIFICATE-----";
    public static final String LINE_SEPARATOR = System.getProperty("line.separator");
	    
    /**
     * 使用私钥对{@code plainText}进行签名
     * @param plainText {@link String}, 明文
     * @param rsaService {@link RSAService}, rsa服务
     * @return {@link String}, 签名数据
     */
    public static String sign(String plainText, RSAService rsaService, String privateKey) 
    		throws IOException, NoSuchAlgorithmException, SignatureException,
    		InvalidKeySpecException, InvalidKeyException {
    	Objects.requireNonNull(plainText, "\"plainText\" cannot be null.");
        Objects.requireNonNull(rsaService, "\"rsaService\" cannot be null.");
        Objects.requireNonNull(privateKey, "\"privateKey\" cannot be null.");
        
        return rsaService.sign(plainText.getBytes("utf-8"), privateKey);
    }
    

}
